package leetcode;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

/**
 * create by duanx 2022/2/7
 *@description： todo
 *@classname: Test3
 *@author: duanx
 *@date: 2022/2/7 9:22
 **/
public class Test4 {

    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            String str;
            while (!(str = reader.readLine().toUpperCase()).isEmpty()){
                int sum = 0;
                for (int i = str.length()-1;i>1;i--){
                    int value = str.charAt(i);
                    int temp;
                    if (value>=65){
                        temp = value -55;
                    }else {
                        temp = value -48;
                    }
                    sum =sum +  (int)Math.pow(16,str.length()-i-1)*temp;
                }
                System.out.println(sum);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
